package main

import (
	"github.com/kardianos/service"
	"log"
)

type program struct{}

func (p *program) Start(s service.Service) error {
	// 服务启动时执行的代码
	log.Println("Service started")
	return nil
}

func (p *program) Stop(s service.Service) error {
	// 服务停止时执行的代码
	log.Println("Service stopped")
	return nil
}

func main() {
	svcConfig := &service.Config{
		Name:        "ExampleService",
		DisplayName: "Example Service",
		Description: "This is an example service.",
	}

	prg := &program{}
	s, err := service.New(prg, svcConfig)
	if err != nil {
		log.Fatal(err)
	}

	logger, err := s.Logger(nil)
	if err != nil {
		log.Fatal(err)
	}

	err = s.Run()
	if err != nil {
		logger.Error(err)
	}
}
